<?php
require_once '../classes/includeAll.php';
$title="Eigene Abfragen";
$head='<script src="../javascript/pagesJavascript/custom.js" type="text/javascript" ></script>'.
      '<link rel="stylesheet" type="text/css" href="../design/css/custom.css">';


if(!$isAdmin)
{
  header("Location: index.php");
  exit();
}

require '../resources/getConnection.php';
$customClass = new Custom($connection);

if(isset($_POST["submit"]) && isset($_POST["custom"]))
{
  $custom = $_POST["custom"];
  if($customClass->AddQueries($custom))
  {
    $configClass = new Config($connection);
    $configClass->EntryExistsOrCreate ("OutOfCustomSync", 1);
  }
}

$customs=$customClass->GetAllCustom();
$connection->disconnectDB();

require '../menu/head.php';
echo '<h1>Eigene Abfragen</h1>';
echo '<form action="custom.php" method="POST">';
echo '<table id="queryTable"><thead><tr><th>Abfragen</th><th>Ger&auml;tetyp</th><th></th></tr></thead><tbody>';
foreach ($customs as $custom) {
  $type="Alle Ger&auml;te";
  switch ($custom[2]) {
    case "PC":
      $type="Computer";
      break;
    case "Printer":
      $type="Drucker";
      break;
  }
echo '<tr>'
  . '<td>'.$custom[1].'</td>'
  . '<td>'.$type.'</td>'  
  . "<td onclick='deleteQuery(this,\"$custom[0]\")'>".'<img src="../design/pictures/delete.png" width="20" height="20" alt="X"/></td>'
  . '</tr>';
}
echo '<tr class="line">'
  . '<td><input class="queryTextbox" type="text" name="custom[0][0]" onchange="changeQueryField(this)" value="" /></td>'
  . '<td><select name="custom[0][1]">'
  . '<option value="1">Alle Geräte</option>'
  . '<option value="2">Computer</option>'
  . '<option value="3">Drucker</option>'
  . '</select></td>'
  . '<td></td>'
  . '</tr>';
echo '</tbody></table>';

echo '<p><input type="submit" value="&Uuml;bernehmen" name="submit" /></p>';
echo '</form>';
require '../menu/footer.php';

